package com.li.blog.controller;


import com.li.blog.common.lang.Result;
import com.li.blog.entity.User;
import com.li.blog.service.UserService;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Liyangjing
 * @since 2021-11-23
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @RequiresAuthentication
    @GetMapping("/")
    public Result index(){
        return Result.succ(userService.getById(1L));
    }

    @PostMapping("/add")
    public Result add( @Validated @RequestBody User user){
        return Result.succ(user);
    }
    @PostMapping("/update")
    public Result alter(@RequestBody User user){
        boolean b = userService.updateById(user);
        if(b){
            return  Result.succ("修改成功!");
        }
        return Result.fail("修改失败!");
    }
}
